var hS : animalHealth = null;
var gO :GameObject;
var died : boolean = false;

function Start(){
  hS = GetComponent("animalHealth");
  // Set all animations to loop
  gO.animation.wrapMode = WrapMode.Loop;
  // except shooting
  gO.animation["dead"].wrapMode = WrapMode.Once;
   
  gO.animation["dead"].layer = 1;
}

function Update(){
  if(!died){
    if(hS.GetHealth() <= 0){
      playAnim("dead");
    }
  else{
      playAnim("walk");
    }
  }
}

function playAnim(anim){
  switch(anim){
    case "dead":
      died = true;
      gO.animation["walk"].wrapMode = WrapMode.Once;
      gO.animation.CrossFade("dead");
      Debug.Log(gO.animation.clip.length);
      yield WaitForSeconds (5);
      hS.death();
    break;
    case "walk":
      gO.animation.CrossFade("walk");
    break;
    default:
    
    break;
    }
}

